export default {
	namespaced:true,
	state:()=>({
		useraddres:JSON.parse(uni.getStorageSync('address')||'{}'),
		token:'',
		userobj:JSON.parse(uni.getStorageSync('userobj')||'{}'),
		code:JSON.parse(uni.getStorageSync('code')||"null")
	}),
	mutations:{
		setaddress(state,obj){//添加地址
			state.useraddres=obj;
			this.commit('user/setStore')
		},
		updateaddres(state,obj){//修改地址
			state.useraddres=obj;
			this.commit('user/setStore')
		},
		setStore(state){//设置缓存
			uni.setStorageSync('address',JSON.stringify(state.useraddres))
		},
		setuserobj(state,obj){//用户登录
			state.userobj=obj;
			this.commit('user/setUserobj')
		},
		setUserobj(state){//设置用户登录缓存
			uni.setStorageSync('userobj',JSON.stringify(state.userobj))
		},
		setCode(state){//设置用code缓存
			uni.setStorageSync('code',JSON.stringify(state.code))
		},
		setUserCode(state,code){
			state.code=code;
			state.token='Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEyLCJpYXQiOjE1MjU0MDIyMjMsImV4cCI6MTUyNTQ4ODYyM30.g-4GtEQNPwT_Xs0Pq7Lrco_9DfHQQsBiOKZerkO-O-o'
			this.commit('user/setCode')
		},
		setToken(state,token){//设置token
			state.token=token;
		}
	},
	getters:{
		addressatr(state){
			if(!state.useraddres.provinceName){return ''}
			return 	state.useraddres.provinceName+state.useraddres.cityName+state.useraddres.countyName+state.useraddres.detailInfo
		}
	},
}